package com.caishi.lkx.user.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.caishi.lkx.common.BaseApi;
import com.caishi.lkx.common.role.Roles;
import com.caishi.lkx.user.model.ConfigModel;
import com.caishi.lkx.user.service.impl.ConfigServiceImpl;
import com.zzw.common.Wrappers;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Tag(name = "系统配置相关接口")
@RestController
@RequestMapping("/user/sys/config")
public class ConfigApi extends BaseApi {

    @Resource
    private ConfigServiceImpl configService;


    @Operation(summary = "通过code获取详情")
    @Roles
    @GetMapping(value = "/detail/{key}", produces = "application/json")
    public Object detail(@PathVariable String key) {
        return configService.getValue(key);
    }

    @PostMapping("/update")
    public ConfigModel add(@ModelAttribute ConfigModel sysConfigModel) {
        return configService.insert(sysConfigModel);
    }

    @PutMapping("/update")
    public ConfigModel edit(@ModelAttribute ConfigModel sysConfigModel) {
        return configService.update(sysConfigModel);
    }

    @GetMapping("/page")
    public IPage<ConfigModel> page(@ModelAttribute Page<ConfigModel> page, @ModelAttribute ConfigModel model) {
        return configService.page(configService.pageProcessing(page), Wrappers.lambdaQuery(model));
    }

    @DeleteMapping("/delete")
    public Boolean delete(@RequestParam Long id) {
        return configService.delete(id);
    }

    @DeleteMapping("/deletes")
    public Boolean deletes(@RequestParam List<Long> ids) {
        return configService.delete(ids);
    }
}
